from flask import Blueprint, request, g
from app.utils import ResponseUtil
from app.trace_utils import get_request_info
from app.session_utils import require_auth

main_bp = Blueprint('main', __name__)

@main_bp.route('/')
def index():
    data = {'message': 'Welcome to Union Form Backend API'}
    return ResponseUtil.success(data=data, message="API is running")

@main_bp.route('/health')
def health_check():
    data = {'status': 'healthy', 'service': 'union-form-backend'}
    return ResponseUtil.success(data=data, message="Service is healthy")

@main_bp.route('/trace-info')
def trace_info():
    """
    Endpoint to get trace information for debugging purposes
    """
    request_info = get_request_info()
    return ResponseUtil.success(data=request_info, message="Trace information retrieved")

@main_bp.route('/protected')
@require_auth
def protected():
    """
    Protected endpoint example that requires authentication
    """
    data = {
        'message': 'This is a protected endpoint',
        'user_id': g.current_user_id,
        'username': g.current_username
    }
    return ResponseUtil.success(data=data, message="Access granted to protected resource")